package com.mpyy.service.purchase;

import com.mpyy.dao.purchase.PurchaseReturnDaoInter;
import com.mpyy.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @version 1.0
 * @Description PurchaseReturnServiceImpl
 * @Author liangxinyu
 * @Date 2022-03-09 13:57
 */
@EnableTransactionManagement
@EnableAspectJAutoProxy
@Service("purchaseReturnServiceImpl")
public class PurchaseReturnServiceImpl implements PurchaseReturnServiceInter {
    @Autowired
    private PurchaseReturnDaoInter purchaseReturnDaoInter;

    /* --------------------------------------------purchase_return.html-------------------------------------------- */

    /* 供货商信息查询 */
    @Override
    public List<SupplierInfo> searchSupplierInfo() {
        return purchaseReturnDaoInter.searchSupplierInfo();
    }

    /* 出货仓库 */
    @Override
    public List<DepotInfo> searchDepotInfo() {
        return purchaseReturnDaoInter.searchDepotInfo();
    }

    /* 供货商类型表查询 */
    @Override
    public List<AddSupplierType> searchSupplierType() {
        return purchaseReturnDaoInter.searchSupplierType();
    }

    /* 供货商类型 + 默认选择 */
    @Override
    public int doUpdateSupplierType(AddSupplierType addSupplierType) {
        return purchaseReturnDaoInter.doUpdateSupplierType(addSupplierType);
    }

    /* 经办人 */
    @Override
    public List<EmployeeInfo> searchHandler() {
        return purchaseReturnDaoInter.searchHandler();
    }

    /* 生成采购退货单、采购退货详情单、修改库存明细表、新增库存变动 */
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED)
    @Override
    public Boolean doUpdateMultipurpose(PurchaseReturn pr, List<PurchaseReturnDesc> pst, List<InventoryDesc> ids, List<InventoryChange> ic) {
        Boolean pd = false;
        int prRow = purchaseReturnDaoInter.doUpdatePurchaseReturnSingle(pr);
        int pstRow = purchaseReturnDaoInter.doUpdatePurchaseReturnDetailsSheet(pst);
        int idsRow = purchaseReturnDaoInter.doUpdateReviseInventoryList(ids);
        int icRow = purchaseReturnDaoInter.doUpdateChangeInNewInventory(ic);
        if(prRow > 0 && pstRow > 0 && idsRow > 0 && icRow > 0){
            pd = true;
        }
        return pd;
    }


    /* --------------------------------------------add_commodity.html-------------------------------------------- */

    /* 添加退货商品 */    /* 商品批次信息 数据表   查询 */
    @Override
    public List<InventoryDesc> addReturnedInfoBtn(String depotId, String supId, String proId, String signProList, String idOrName,String proTypeId) {
        return purchaseReturnDaoInter.addReturnedInfoBtn(depotId,supId,proId,signProList,idOrName,proTypeId);
    }


    /* --------------------------------------------原始单号-------------------------------------------- */

    @Override
    public List<PurchaseStock> seachOriginalOrderNumber(String startDate, String endDate){
        return purchaseReturnDaoInter.seachOriginalOrderNumber(startDate,endDate);
    }

    @Override
    public List<PurchaseStockDesc> seachToCommodityByOrder(String purStoId) {
        return purchaseReturnDaoInter.seachToCommodityByOrder(purStoId);
    }

}
